﻿using System;
using System.Collections.Generic;
using GameFramework.Battle.Core;
using Gameplay.PVE.Utils;
using RootMotion.FinalIK;
using UnityEngine;

namespace Gameplay.PVE.Survivor
{
    public class ChangePropertyElement: ElementBase
    {
        public override void Execute()
        {
            var subType = (EBattleElementSubType)config.sub_type;
            if (subType == EBattleElementSubType.ChangeSpeed)
            {
                target.AddSpeedRatio(config.value);
            }
            else if (subType == EBattleElementSubType.ChangeBullet)
            {
                var beforeBulletId = config.extra_param[0];
                var afterBulletId = config.extra_param[1];
                target.SetReplaceBullet(beforeBulletId,afterBulletId);
            }
            else if (subType == EBattleElementSubType.ExtraBullet)
            {
                var beforeBulletId = config.extra_param[0];
                var afterBulletId = config.extra_param[1];
                target.SetExtraBullet(beforeBulletId,afterBulletId);
            }
            else if (subType == EBattleElementSubType.ExtraChildSkill)
            {
                var skillId = config.extra_param[0];
                var newSkillId = config.extra_param[1];
                target.AddChildSkill(skillId,newSkillId);
            }
        }

        public override void OnFree()
        {
            var subType = (EBattleElementSubType)config.sub_type;
            if (subType == EBattleElementSubType.ChangeSpeed)
            {
                target.AddSpeedRatio(-config.value);
            }
            else if (subType == EBattleElementSubType.ChangeBullet)
            {
                var beforeBulletId = config.extra_param[0];
                var afterBulletId = config.extra_param[1];
                target.SetReplaceBullet(beforeBulletId,-1);
            }
            else if (subType == EBattleElementSubType.ExtraBullet)
            {
                var beforeBulletId = config.extra_param[0];
                var afterBulletId = config.extra_param[1];
                target.SetExtraBullet(beforeBulletId,-1);
            }
            else if (subType == EBattleElementSubType.ExtraChildSkill)
            {
                var skillId = config.extra_param[0];
                var newSkillId = config.extra_param[1];
                target.RemoveChildSkill(skillId,newSkillId);
            }
        }

        public override bool IsImmediate()
        {
            return false;
        }
    }
}
